var appPackageName="com.kuaishou.nebula";
auto.waitFor();
launch(appPackageName);
sleep(4000);
youngWin();
newVersion()
i = 1;
while (true) {
    toast("滑动" + i + '次')
    WidthOne = random(300, 800);
    HeightOne = random(1600, 1800);
    WidthTwo = random(300, 800);
    HeightTwo = random(300, 500);
    timeGo = random(500, 800);
    timeNext = random(4000, 7000);
    randomStar();
    swipe(WidthOne, HeightOne, WidthTwo, HeightTwo, timeGo);
    sleep(timeNext);
    i++;
}

/**如果弹出青少年窗口，点击 */
function youngWin() {
    if (youngWin = text("我知道了").exists()) {
        youngWin.click();
    };
}

/**随机点赞并休息一秒 */
function randomStar() {
    index = random(1, 5);
    if (index == 3) {
        star()
    }
    sleep(1000);
}

//检测到新版本跳过
function newVersion() {
    if (newVersion = text("以后再说").exists()) {
        newVersion.click();
    };
}

/**
 * 自动提交评论
 * content str 评论内容，默认为666
*/
function autoComment(content) {
    id('pz').findOnce().click();
    sleep(1000);
    b = id('pz').findOnce().bounds();
    sleep(1000);
    click(b.centerX(), b.centerY());
    sleep(1000);
    setText(content);
    sleep(1000);
    click(b.centerX(), b.centerY());
    sleep(1000);
    click(device.width - 80, b.centerY());
    sleep(1000);
    back();
}

function star(){
    random_x = getRndInteger(300,600)
    random_y = getRndInteger(600,1500)
    for(var i = 0; i < 2; i++){
        //点击位置(500, 1000), 每次用时1毫秒
        press(random_x,random_y, 10);
        // click(random_x,random_y)
      }
 }

 function getRndInteger(min, max) {
    return Math.floor(Math.random() * (max - min + 1) ) + min;
}